<style type="text/css">
  .layui-color-red{color: red;}
  .authorize-changer-show{
    display: block;
  }
  .authorize-changer-hide{
    display: none;
  }
</style>
{php}
{//var_dump($data['dept_qrcode']);}
{/php}


<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
    <div class="layui-card-body">
      <div class="layui-row layui-col-space8" style="">
  <div class="layui-col-md4">
   
  </div>
  <div class="layui-col-md4" style="margin-left: 40px;">
   <div id="qrcode" class="text-center"></div>
  </div>
  <div class="layui-col-md4">
   
  </div>
</div>
            <div class="layui-form-item text-center">

<span>请打开微信扫一扫或分享二维码,添加员工</span>
        </div>


    </div>
    <div class="layui-form-item text-center">
       <!--  <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button> -->
         <button class="layui-btn layui-btn-danger  margin-right-40" type='button' data-close>关 闭</button> 
    </div>

</form>

    <script language="JavaScript">
 require(['qrcode'], function () {

  var addurl = '{$data.dept_qrcode}';
  console.log(addurl)
new QRCode(document.getElementById("qrcode"),{
    text: addurl,
    width: 160,
    height: 160,
    colorDark : "#000000",
    colorLight : "#ffffff",
    correctLevel : QRCode.CorrectLevel.H
});

 });
    layui.use(['layer', 'jquery', 'form'], function () {
      var layer = layui.layer,
              $ = layui.jquery;
            form = layui.form;
        /**选择用户后搜索**/
      form.on('select(watch)', function(data){
        console.log(data)
            $.ajax({
              url:"{:url('company/user/getuserlist')}",
              data:{id:data.value},
              type:'post',
              async: false,
              dataType:'json',
              success:function(res) {
                var reres = JSON.parse(res)
                console.log(reres)
                if(reres.data.roleid==2){
                  $('.authorize-changer').css({'display':'block'})
                }else{
                  $('.authorize-changer').css({'display':'none'})
                  $('input[name="ch_role"]').val('off');
                }
                $('#searchname').val(reres.data.name)
                $("input[name='contact_phone']").val(reres.data.mobile)
                $("input[name='contact_mail']").val(reres.data.email)
                $("input[name='userid']").val(reres.data.id)
              }
          })
        });
        /**选择手机后搜索**/
      form.on('select(watchphone)', function(data){
        console.log(data)
            $.ajax({
              url:"{:url('company/user/getuserlist')}",
              data:{id:data.value},
              type:'post',
              async: false,
              dataType:'json',
              success:function(res) {
                var reres = JSON.parse(res)
                console.log(reres)
                try{
                  if(reres.data.roleid==2){
                    $('.authorize-changer').css({'display':'block'})
                  }else{
                    $('.authorize-changer').css({'display':'none'})
                    $('input[name="ch_role"]').val('off');
                  }
                }catch(error){
                    $('.authorize-changer').css({'display':'none'})
                    $('input[name="ch_role"]').val('off');
                }
                $('#searchname').val(reres.data?reres.data.name:'')
                $("input[name='contact_phone']").val(reres.data?reres.data.mobile:'')
                $("input[name='contact_mail']").val(reres.data?reres.data.email:'')
                $("input[name='userid']").val(reres.data?reres.data.id:'')
              }
          })
        });
        /**选择公司后搜搜部门**/
        form.on('select(companyid)', function(data){
        console.log(data)
            $('input[name="companyid"]').val(data.value)
            $('#deptlist').html('')
            form.render('select')
            $.ajax({
              url:"{:url('company/department/getdeptlist')}",
              data:{companyid:data.value},
              type:'post',
              async: false,
              dataType:'json',
              success:function(res) {
                // if(eval('{$userinfo["db1"]["authorize"]}')==1){
                //   $('.authorize-changer').css({'display':'block'})
                // }
                var reres = JSON.parse(res)
                var option = ''
                console.log(reres)
                for (var i = 0; i < reres.data.length; i++) {
                    option = option+"<option data-is_security="+reres.data[i].is_security+" value="+reres.data[i].id+">"+reres.data[i].dept_name+"</option>"
                }
                $('#deptlist').append(option)

              }
          }) 
        form.render('select')
      });

        /**选择部门后**/
        form.on('select(departmentid)', function(data){
            console.log(data)
            var is_security = $(data.elem).find("option:selected").attr("data-is_security")
            console.log(is_security)
            console.log(data.elem[data.elem.selectedIndex]); 
            if(is_security==1){
                $('input[name="is_security"]').val(1)   
            }else{
                $('input[name="is_security"]').val(0) 
            }
            console.log($('input[name="is_security"]').val());
      });
        
        // $('#searchuser').change(function(){
        //     console.log(2)
        // })
        
        $("#searchname").on("input",function(e){
            $("#searchuserlist").next().find("dl").css({ "display": "block" });
            console.log(e.delegateTarget.value);
            $('#searchuserlist').html('')
            form.render('select')
            if(e.delegateTarget.value==''){return;}
            $.ajax({
              url:"{:url('company/user/getuserlist')}",
              data:{name:e.delegateTarget.value},
              type:'post',
              async: false,
              dataType:'json',
              success:function(res) {
                var reres = JSON.parse(res)
                var option = ''
                for (var i = 0; i < reres.data.length; i++) {
                    option = option+"<option value="+reres.data[i].id+">"+reres.data[i].name+"</option>"
                }
                console.log(reres)
                $('#searchuserlist').append(option)
              }
          })
            form.render('select')
        });

          $("#searchphone").on("input",function(e){
            $("#searchphonelist").next().find("dl").css({ "display": "block" });
            console.log(e.delegateTarget.value);
            $('#searchphonelist').html('')
            form.render('select')
            if(e.delegateTarget.value==''){return;}
            $.ajax({
              url:"{:url('company/user/getuserlist')}",
              data:{'phone':e.delegateTarget.value,'type':'phone'},
              type:'post',
              async: false,
              dataType:'json',
              success:function(res) {
                console.log(res)
                var reres = JSON.parse(res)
                var option = ''
                for (var i = 0; i < reres.data.length; i++) {
                    option = option+"<option value="+reres.data[i].id+">"+reres.data[i].mobile+"</option>"
                }
                console.log(reres)
                $('#searchphonelist').append(option)
              }
          })
            form.render('select')
        });
    });



    </script>
<script>form.render();</script>

